package cn.djb.day1;

import java.util.Stack;

class MinStack {

    private Stack<Integer> stack, sortStack;

    /**
     * initialize your data structure here.
     */
    public MinStack() {
        stack = new Stack<>();
        sortStack = new Stack<>();
    }

    public void push(int x) {
        stack.push(x);
        if (sortStack.isEmpty() || sortStack.peek() >= x) {
            sortStack.push(x);
        }

    }

    public void pop() {
        Integer pop = stack.pop();
        if (sortStack.peek().equals(pop)) {
            sortStack.pop();
        }

    }

    public int top() {
        return stack.peek();
    }

    public int min() {
        return sortStack.peek();
    }

    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        System.out.println(minStack.min());
        minStack.pop();
        System.out.println(minStack.top());
        System.out.println(minStack.min());
    }
}